package com.larissa.android.quiz;

import android.app.Application;

import com.larissa.android.quiz.question.Question;
import com.larissa.android.quiz.question.QuestionRepository;

public class QuizApplication extends Application {
    private QuestionRepository repository;

    @Override
    public void onCreate() {
        super.onCreate();
        QuestionRepository.init(this);
        repository = QuestionRepository.getInstance();
        initializeList();
    }



    private void initializeList() {
        repository.readQuestionsFromDB();
        if(repository.getGeoQuestions().isEmpty()) {
            String[] q, a;
            q = getResources().getStringArray(R.array.geography_question);
            a = getResources().getStringArray(R.array.geography_answer);
            for (int i = 0; i < Math.min(q.length, a.length); i++) {
                Question question = new Question(q[i], a[i], Question.GEO);
                repository.getGeoQuestions().add(i, question);
                repository.getQuestionsToBeInserted().add(question);
            }
        }
        if(repository.getMathQuestions().isEmpty()) {
            String[] q, a;
            q = getResources().getStringArray(R.array.mathematics_question);
            a = getResources().getStringArray(R.array.mathematics_answer);
            for (int i = 0; i < Math.min(q.length, a.length); i++) {
                Question question = new Question(q[i], a[i], Question.MATH);
                repository.getMathQuestions().add(i, question);
                repository.getQuestionsToBeInserted().add(question);
            }

        }
    }
}
